package org.tale.mscp.notify.services.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.tale.mscp.notify.entity.AnnualLeave;
import org.tale.mscp.notify.mapper.AnnualLeaveMapper;
import org.tale.mscp.notify.services.ILeaveQueryService;
import org.tale.mscp.notify.utils.ParameterException;

import java.util.List;

/**
 * @program: mscp
 * @author: tale-mi
 * @description:
 * @create: 2019/6/15 17:21
 **/

@Service
@DS("hr")
public class LeaveQueryServiceImpl implements ILeaveQueryService {
    @Autowired
    AnnualLeaveMapper annualLeaveMapper;

    public LeaveQueryServiceImpl() {
    }

    @Override
    public List<AnnualLeave> getAvailableAnnualLeave(String name, String year) throws ParameterException {
        if (!StringUtils.isEmpty(name) && !StringUtils.isEmpty(year)) {
            LambdaQueryWrapper<AnnualLeave> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(AnnualLeave::getUserName, name).eq(AnnualLeave::getYears, year);
            return this.annualLeaveMapper.selectList(lambdaQueryWrapper);
        } else {
            throw new ParameterException("不允许传递空参数");
        }
    }
}
